<template>
	<div style="display: inline-block;position: relative;width:auto;">
		<i class="el-icon-rank drag-widget" style="position: absolute;left: 0px;top:-6px;z-index: 100;" v-show="selected"></i>
		<el-button @click.stop="onClickHandler" ref="buttonComponent" size="small">{{componentModel.labelExpression}}</el-button>
	</div>
</template>

<script>
	import utils from '@/utils/utils.js';
	import formDesignerUtil from '@/utils/formDesignerUtil.js';
	export default {
		name: "DesignButtonComponent",
		props: [
			"componentModel"
		],
		beforeMount() {
			if (this.componentModel.labelExpression==undefined){
				formDesignerUtil.setComponentModelPropValue(this.componentModel,"labelExpression","按钮");
			}
		},
		data() {
			return {
				selected:false,
				"propertySet": [{
						"key": "ID",
						"label": "ID",
						"editor": "label"
					},
					{
						"key": "labelExpression",
						"label": "标签",
						"editor": "text"
					},
					{
						"key": "readonly",
						"label": "只读逻辑",
						"editor": "textarea"
					},
					{
						"key": "visible",
						"label": "显示逻辑",
						"editor": "textarea"
					},
					{
						"key": "onClickExpression",
						"label": "单击事件",
						"editor": "textarea"
					},
					{
						"key": "colorType",
						"label": "颜色类型",
						"editor": "select",
						"selectItems":[
							{"name":"","value":""},
							{"name":"primary","value":"primary"},
							{"name":"success","value":"success"},
							{"name":"info","value":"info"},
							{"name":"warning","value":"warning"},
							{"name":"danger","value":"danger"},
						]
					},{
						"key": "confirmMessage",
						"label": "确认消息",
						"editor": "textarea"
					},{
						"key": "clientPageCode",
						"label": "客户端页面",
						"editor": "text"
					},{
						"key": "serverPageCode",
						"label": "服务端页面",
						"editor": "text"
					},{
						"key": "para1",
						"label": "参数1",
						"editor": "textarea"
					},{
						"key": "para2",
						"label": "参数2",
						"editor": "textarea"
					}
				]
			}
		},
		inject:['children'],
		mounted() {
			this.children.push(this);
		},beforeUnmount() {
			utils.removeArrayElement(this.children,this);
		},
		methods: {
			onClickHandler() {
				formDesignerUtil.componentClickHandler(this);
			},
			getPropertyValue(propertyKey) {
				if (propertyKey == "ID") {
					return formDesignerUtil.getComponentModelPropValue(this.componentModel,"id");
				} else if (propertyKey == "labelExpression") {
					return formDesignerUtil.getComponentModelPropValue(this.componentModel,"labelExpression");
				}
				return formDesignerUtil.getComponentModelCommonValue(this.componentModel,propertyKey);
			},
			setPropertyValue(propertyKey, propertyValue) {
				formDesignerUtil.setComponentModelCommonValue(this.componentModel,propertyKey, propertyValue);
				if (propertyKey == "labelExpression") {
					formDesignerUtil.setComponentModelPropValue(this.componentModel,"labelExpression",propertyValue);
				}
			},setSelected(selected){
				this.selected=selected;	
			}
		}
	}
</script>

<style>
</style>
